from benchmarks.maxcut import Benchmark
import numpy as np
import matplotlib.pyplot as plt

from utils.tsne import tsne_plot

config = {
    'n_dim': 2000
}
bm = Benchmark(config)
x = np.random.randint(0, 2, (2000))
res = bm.evaluate(x)
print(res)

from optimizer.qsbpso import Optimizer


config = {
    'n_run': 6000,
    'n_part': 10,
    'show': 0,
    'benchmark': bm,
    'n_group': 1,
    'n_dim': bm.ising_equivalent.dimension,
    'pos_max': 2,
    'pos_min': -2,
    'max_v': 2,
    'min_v': -2,
    'fe_max': 60000,
    'record_per_fe': 300,
    'ising_J': bm.ising_equivalent.J,
}
optimizer = Optimizer(config)
optimizer.run()
print(optimizer.result_cache)

xs = []
ys = []
for res in optimizer.result_cache:
    xs.append(res['fe_num'])
    ys.append(res['best'])

plt.plot(xs, ys)
plt.rcParams['font.sans-serif'] = ['SimHei']  # 显示中文标签
plt.rcParams['axes.unicode_minus'] = False
plt.legend()

plt.title(optimizer.optimizer_name)
plt.ylabel('最优值（以10为底对数）')
plt.xlabel('迭代次数')
plt.show()
plt.close()

tsne_plot(np.array(optimizer.history_best_x_list))

